package com.dha.caodangcongnghe;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.Toast;

import com.dha.adapter.ThongBaoAdapter;
import com.dha.asynctask.XemThongBaoChiTietAsyncTask;
import com.dha.model.ThongBaoModel;
import com.dha.status.NetworkStatus;

public class XemThongBaoChiTiet extends ActionBarActivity {
	private NetworkStatus networkStatus;

	private ListView lv_ThongBao;
	public static ArrayList<ThongBaoModel> arr;
	public static ThongBaoAdapter adapter;

	// private QuangCao quangCao;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_thong_bao);
		arr = new ArrayList<ThongBaoModel>();
		lv_ThongBao = (ListView) findViewById(R.id.lv_ThongBao);
		adapter = new ThongBaoAdapter(this, R.layout.layout_thongbao_custom,
				arr);

		lv_ThongBao.setAdapter(adapter);

		// quangCao = new QuangCao(this, XemThongBao.this);

		networkStatus = new NetworkStatus(getBaseContext());

		if (networkStatus.isConnected()) {
			// Nhan gia tri tu intent giao vien put qua
			//mo asynctask 
			Intent i = getIntent();
			int maThongBao = Integer.parseInt(i.getStringExtra("maThongBao"));
			Log.i("hehe",maThongBao+"");
			XemThongBaoChiTietAsyncTask xemThongBaoDayDuAsyncTask = new XemThongBaoChiTietAsyncTask(
					XemThongBaoChiTiet.this, maThongBao);
			xemThongBaoDayDuAsyncTask.execute();

		} else {
			Intent intentLoi = new Intent("SuCoVeKetNoiMang");
			startActivity(intentLoi);
		}

	}

//	@Override
//	public boolean onCreateOptionsMenu(Menu menu) {
//		// Inflate the menu; this adds items to the action bar if it is present.
//		getMenuInflater().inflate(R.menu.menu_thong_bao, menu);
//		return true;
//	}

//	@Override
//	public boolean onOptionsItemSelected(MenuItem item) {
//		switch (item.getItemId()) {
//		case R.id.mn_ThongBao_XemThongBaoMoi:
//			if (networkStatus.isConnected()) {
//				Intent intentThongBao = new Intent(getBaseContext(),
//						XemThongBaoChiTiet.class);
//				startActivity(intentThongBao);
//				this.finish();
//			} else {
//				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
//				startActivity(intentLoi);
//			}
//			break;
//		case R.id.mn_ThongBao_XemTheoTenGiaoVien:
//			if (networkStatus.isConnected()) {
//				Intent intentDanhSachGiaoVien = new Intent("DanhSachGiaoVien");
//				startActivity(intentDanhSachGiaoVien);
//			} else {
//				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
//				startActivity(intentLoi);
//			}
//			break;
//		case R.id.mn_ThongBao_XemTheoNgay:
//			Intent itentChonNgay = new Intent("ChonNgay");
//			startActivity(itentChonNgay);
//			break;
//		case R.id.mn_ThongBao_XemTheoNgayVaGiaoVien:
//			if (networkStatus.isConnected()) {
//				Intent intentNgayVaGiaoVien = new Intent(
//						"XemThongBaoTheoNgayVaGiaoVien");
//				startActivity(intentNgayVaGiaoVien);
//			} else {
//				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
//				startActivity(intentLoi);
//			}
//			break;
//		default:
//			Toast.makeText(getBaseContext(), "Không hỗ trợ", Toast.LENGTH_SHORT)
//					.show();
//		}
//		return super.onOptionsItemSelected(item);
//	}

}
